using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;
using WindowsGame1.SpriteClasses;
using System.Xml;

namespace WindowsGame1
{
    class TileMapComponent : Microsoft.Xna.Framework.DrawableGameComponent
    {
        TileMap tileMap;
        Random random = new Random();
        SpriteBatch spriteBatch;
        ContentManager Content;
        Tileset tileset;
        Texture2D texture;
        Texture2D itemTexture;
        int mapWidth;
        int mapHeight;
        static int widthInPixels;
        static int heightInPixels;
        List<ItemSprite> items = new List<ItemSprite>();

        public TileMapComponent(TileMap tileMap, Tileset tileset, Game game)
            : base(game)
        {
            spriteBatch = Game1.TileSpriteBatch;
            Content =
            (ContentManager)Game.Services.GetService(typeof(ContentManager));
            this.tileMap = tileMap;
            this.tileset = tileset;
            mapWidth = tileMap.MapWidth;
            mapHeight = tileMap.MapHeight;
            LoadContent();
        }

        public static int WidthInPixels
        {
            get { return widthInPixels; }
        }

        public static int HeightInPixels
        {
            get { return heightInPixels; }
        }

        protected override void LoadContent()
        {
            texture = Content.Load<Texture2D>(@"TileSets\" + tileset.TextureName);
            itemTexture = Content.Load<Texture2D>(@"Items\chest");
            base.LoadContent();
        }

        public override void Initialize()
        {
            base.Initialize();
        }

        public override void Update(GameTime gameTime)
        {
            widthInPixels = mapWidth * TileEngine.TileWidth;
            heightInPixels = mapHeight * TileEngine.TileHeight;
            base.Update(gameTime);
        }

        public override void Draw(GameTime gameTime)
        {
            tileMap.Draw(spriteBatch, texture, tileset);
            foreach (ItemSprite item in items)
            {
                item.Draw(gameTime);
            }
            base.Draw(gameTime);
        }

        public void Hide()
        {
            Visible = false;
            Enabled = false;
        }

        public void Show()
        {
            Visible = true;
            Enabled = true;
        }
    }
}